/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.woundedwolf.android.tumbleweed.elements;

/**
 *
 * @author FlameDuck
 */
public class Vector2D
{
	private float xpos;
	private float ypos;

	public Vector2D(float xpos, float ypos)
	{
		this.xpos = xpos;
		this.ypos = ypos;
	}

	public Vector2D(float angle)
	{
		double rad = angle * Math.PI / 180d;
		xpos = (float) Math.cos(rad);
		ypos = (float) Math.sin(rad);
	}

	public Vector2D scale(float scalar)
	{
		this.xpos *= scalar;
		this.ypos *= scalar;
		return this;
	}

	public double getLength()
	{
		return Math.sqrt(xpos * xpos + ypos * ypos);
	}

	public float getXpos() {
		return xpos;
	}

	public void setXpos(float xpos) {
		this.xpos = xpos;
	}

	public float getYpos() {
		return ypos;
	}

	public void setYpos(float ypos) {
		this.ypos = ypos;
	}

	public void add(Vector2D otherVector)
	{
		this.xpos += otherVector.xpos;
		this.ypos += otherVector.ypos;
	}
}
